<?php

  /*

      TravianWAP
      Copyright (c) 2007-08 by Ananas - All rights reserved
      http://n00bz.biz/travianwap/
      Contact: uroskn@gmail.com

      --------------------------------------------------------------------------

      This program is free software: you can redistribute it and/or modify
      it under the terms of the GNU  General Public License as published by
      the Free Software Foundation, either version 3 of the License, or
      (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU  General Public License
      along with this program. If not, see http://www.gnu.org/licenses/.

  */

  function ps($separator = "&")
  {
    return $separator.htmlspecialchars(SID);
  }

  session_start();
  error_reporting(0);
  require("travian.php");

  if (!empty($_GET["login"]))
  {
    $_SESSION = travian_create($_GET["user"], $_GET["pass"], $_GET["server"]);
    if (!$_SESSION) $error = "Unable to login!";
    else
    {
      $location = $_SERVER["HTTP_HOST"];
      header("Location: http://{$_SERVER["HTTP_HOST"]}".str_replace('\\', '/', dirname($_SERVER["SCRIPT_NAME"]))."/main.php?mod=main".ps());
      exit();
    }
  }
  
  if (!empty($_GET["message"])) $error = htmlspecialchars($_GET["message"]);

  require("display.php");

  echo '<strong>TravianWAP - Login</strong><br/><br/>';

  if (!empty($error)) echo "<b>$error</b><br/><br/>";

  $pfields = array(
    "pass"   => '$(pass)',
    "user"   => '$(user)',
    "server" => '$(server)',
    'login'  => '1'
  );
  print_form_top("index.php", $pfields, "get");

?>
Username:<br/>
<input name="user" type="text" value=""/><br/>
Password:<br/>
<input name="pass" type="password" value=""/><br/>
Server:<br/>
<input name="server" type="text" value=""/><br/>
<br/>
<?php

  print_form_bottom("Login");

?>
